package com.ibeeking.found.open.b.rest.controller.v1;

import com.ibeeking.found.open.api.common.dto.GoodsInfoDTO;
import com.ibeeking.found.open.api.common.dto.GoodsListDTO;
import com.ibeeking.found.open.api.common.query.GoodsListQuery;
import com.ibeeking.found.open.b.rest.service.IGoodsService;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.page.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

/**
 * @ClassName GoodsController控制器
 * @Description
 * @Author ibeeking
 * @Date 2021-06-02 18:15
 **/
@RestController
@RequestMapping("/v1/api/goods")
public class GoodsController {

    @Resource
    private IGoodsService goodsServiceImpl;

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "商品列表查询")
    @PostMapping(value = "/list")
    public Page<GoodsListDTO> goodsList(@RequestBody @Validated GoodsListQuery query) {
        return goodsServiceImpl.goodsList(query);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "商品详情查询")
    @GetMapping(value = "/info/{goodsId}")
    public GoodsInfoDTO goodsInfo(@PathVariable @NotNull(message = "商品id不能为空") Long goodsId) {
        return goodsServiceImpl.goodsInfo(goodsId);
    }
}
